/*
     Copyright 2007 Joseph M. Ferner

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;

namespace OpenServers.Net.FtpServer {
    ///<summary>
    /// Looks up response messages.
    ///</summary>
    public class Messages : IMessages {
        /// <summary>
        /// Bad sequence of commands.
        /// </summary>
        public virtual string Get503() {
            return "503 Bad sequence of commands.\r\n";
        }

        /// <summary>
        /// Syntax error, command unrecognized.
        /// </summary>
        public virtual string Get500() {
            return "500 Syntax error, command unrecognized.\r\n";
        }

        /// <summary>
        /// Requested action not taken. File unavailable (e.g., file not found, no access).
        /// </summary>
        public virtual string Get550(Reason550 reason) {
            string reasonString;
            switch (reason) {
                case Reason550.AccessDenied:
                    reasonString = "Access Denied.";
                    break;
                case Reason550.FileAlreadyExists:
                    reasonString = "File already exists.";
                    break;
                case Reason550.FileNotFound:
                    reasonString = "File not found.";
                    break;
                default:
                    throw new ApplicationException("invalid reason");
            }
            return string.Format("550 Requested action not taken. {0}\r\n", reasonString);
        }

        /// <summary>
        /// Requested action not taken. File name not allowed.
        /// </summary>
        public string Get553() {
            return "553 Requested action not taken.\r\n";
        }

        /// <summary>
        /// Requested file action okay, completed.
        /// </summary>
        public virtual string Get250() {
            return "250 Requested file action okay, completed..\r\n";
        }

        /// <summary>
        /// Closing data connection.
        /// Requested file action successful (for example, file transfer or file abort).
        /// </summary>
        public virtual string Get226() {
            return "226 Transfer completed.\r\n";
        }

        /// <summary>
        /// System status, or system help reply.
        /// </summary>
        public virtual string Get211(Reason211 reason) {
            switch (reason) {
                case Reason211.NoFeatures:
                    return "211 No features.\r\n";
                case Reason211.ExtensionsSupported:
                    return "211-Extensions supported:\r\n";
                case Reason211.End:
                    return "211 END\r\n";
                default:
                    throw new ApplicationException("invalid reason");
            }
        }

        /// <summary>
        /// File status okay; about to open data connection.
        /// </summary>
        /// <param name="arguments">Name of file</param>
        public virtual string Get150(string arguments) {
            return string.Format("150 Opening ASCII mode data connection for {0}.\r\n", arguments);
        }

        /// <summary>
        /// "PATHNAME" created.
        /// </summary>
        public virtual string Get257(string path, Reason257 reason) {
            string reasonString;
            switch (reason) {
                case Reason257.DirectoryCreated:
                    reasonString = "Directory created";
                    break;
                case Reason257.CurrentDirectory:
                    reasonString = "Current directory";
                    break;
                default:
                    throw new ApplicationException("invalid reason");
            }
            return string.Format("257 \"{0}\" {1}.\r\n", path, reasonString);
        }

        /// <summary>
        /// User logged in, proceed.
        /// </summary>
        public virtual string Get230() {
            return "230 User logged in, proceed.\r\n";
        }

        /// <summary>
        /// Not logged in.
        /// </summary>
        public string Get530() {
            return "530 Not logged in.\r\n";
        }

        /// <summary>
        /// Syntax error in parameters or arguments.
        /// </summary>
        public virtual string Get501() {
            return "501 Syntax error in parameters or arguments.\r\n";
        }

        /// <summary>
        /// Command okay.
        /// </summary>
        public virtual string Get200() {
            return "200 PORT command successful.\r\n";
        }

        /// <summary>
        /// Command not implemented.
        /// </summary>
        public virtual string Get502() {
            return "502 Command not implemented.\r\n";
        }

        /// <summary>
        /// Service ready for new user.
        /// </summary>
        public virtual string Get220() {
            return "220 Hello\r\n";
        }

        /// <summary>
        /// User name okay, need password.
        /// </summary>
        public virtual string Get331() {
            return "331 User name okay, need password.\r\n";
        }

        /// <summary>
        /// NAME system type.
        /// Where NAME is an official system name from the list in the
        /// Assigned Numbers document.
        /// </summary>
        /// <param name="systemTypeString">Name of system</param>
        public virtual string Get215(string systemTypeString) {
            return string.Format("215 {0}\r\n", systemTypeString);
        }

        /// <summary>
        /// Requested file action pending further information.
        /// </summary>
        public virtual string Get350() {
            return "350 Requested file action pending further information.\r\n";
        }

        /// <summary>
        /// Service closing control connection.
        /// </summary>
        public virtual string Get221() {
            return "221 Goodbye.\r\n";
        }
    }
}
